<?php
 class App_SetLanguage
{
  public static function setLanguage($request) {
    $language=$request->getParam('language','');
 
    if (empty($language)){
     $session = Zend_Registry::get('session_localAds');
     $language = isset($session->language)?$session->language:"en";
     }

     switch ($language){
      case 'en': $lang_str='en_US'; break;
      case 'cn': $lang_str='zh_CN'; break;
     default: $lang_str='en_US';
     }
 
    $locale  = new Zend_Locale($lang_str);
 
    Zend_Registry::set('Zend_Locale', $locale);
 
    $region = $locale->getRegion();
    $lang = $locale->getLanguage();
 
    $translationFile = APPLICATION_PATH . "/languages/$lang.php";
    $translate = new Zend_Translate('array', $translationFile, $lang);
    Zend_Registry::set('Zend_Translate', $translate);
 
    $session = Zend_Registry::get('session_localAds');
    $session->language = $language; //add to session
    }
 }
